package com.mzba.place.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mzba.place.BasicActivity;
import com.mzba.place.R;
import com.mzba.place.entity.SafecardEntity;
/**
 * 
 * @author 06peng
 *
 */
public class GridCardAdapter extends BaseAdapter {

	private Context context;
	private List<SafecardEntity> treeNode = null;
	public int width;
	public int height;

	public GridCardAdapter(Context activity, List<SafecardEntity> nodeVector) {
		this.context = activity;
		this.treeNode = nodeVector;
		width = BasicActivity.CanvasWidth;
		height = BasicActivity.CanvasHeight;
	}

	@Override
	public int getCount() {
		return treeNode.size();
	}

	@Override
	public Object getItem(int arg0) {
		return treeNode.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context).inflate(R.layout.color_lump_layout, null);
		TextView tvColorLumpTitle1 = (TextView) convertView.findViewById(R.id.card_count);
		TextView tvColorLumpTitle2 = (TextView) convertView.findViewById(R.id.card_description);
		LinearLayout colorLayout = (LinearLayout) convertView.findViewById(R.id.colorlump_layout);
		SafecardEntity node = treeNode.get(position);
		int percent = node.getPercent();
		if (percent > 0 && percent <= 10) {
			colorLayout.setBackgroundColor(Color.rgb(99, 176, 70));
		} else if (percent > 10 && percent <= 20) {
			colorLayout.setBackgroundColor(Color.rgb(99, 230, 70));
		} else if (percent > 20 && percent <= 30) {
			colorLayout.setBackgroundColor(Color.rgb(111, 241, 71));
		} else if (percent > 30 && percent <= 40) {
			colorLayout.setBackgroundColor(Color.rgb(180, 235, 54));
		} else if (percent > 40 && percent <= 50) {
			colorLayout.setBackgroundColor(Color.rgb(229, 224, 72));
		} else if (percent > 50 && percent <= 60) {
			colorLayout.setBackgroundColor(Color.rgb(237, 200, 50));
		} else if (percent > 60 && percent <= 70) {
			colorLayout.setBackgroundColor(Color.rgb(240, 163, 33));
		} else if (percent > 70 && percent <= 80) {
			colorLayout.setBackgroundColor(Color.rgb(235, 118, 4));
		} else if (percent > 80 && percent <= 90) {
			colorLayout.setBackgroundColor(Color.rgb(238, 60, 12));
		} else if (percent > 90 && percent <= 100) {
			colorLayout.setBackgroundColor(Color.rgb(226, 30, 14));
		} else if (percent == 0) {
			colorLayout.setBackgroundColor(Color.rgb(226, 30, 14));
		}
		
		if (node.getAll_count() == 0) {
			tvColorLumpTitle1.setTextSize(44.0f);
			tvColorLumpTitle1.setTextColor(Color.GREEN);
			tvColorLumpTitle1.setText("+");
			tvColorLumpTitle2.setText("安全卡片");
			tvColorLumpTitle2.setLines(1);
			colorLayout.setBackgroundColor(Color.WHITE);
		} else {
			tvColorLumpTitle1.setTextSize(18.0f);
			tvColorLumpTitle1.setTextColor(Color.WHITE);
			tvColorLumpTitle1.setText("危险指数:" + node.getPercent());
			tvColorLumpTitle2.setText(node.getAddress());
			tvColorLumpTitle2.setTextColor(R.color.blubg);
		}
		return convertView;
	}
	
	
}
